// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.common.base;

import com.dustedpixels.asm.RepeatableClassLoader;
import com.google.common.base.Preconditions;


/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class Repeatables {
  /**
   * Returns a {@code Repeatable} which will run given {@code Runnable} given
   * number of times.
   * 
   * @param runnable a runnable to repeat
   * @return repeatable
   */
  public static Repeatable running(final Runnable runnable) {
    return new Repeatable() {
      public void repeat(int times) {
        Preconditions.checkArgument(times >= 0, "Negative number of times");
        
        while (times != 0) {
          runnable.run();
          times--;
        }
      }
    };
  }
}
